package com.itbour.service.tg.impl;

import java.util.List;
import java.util.Map;

import com.itbour.com.page.JspPage;
import com.itbour.com.page.Page;
import com.itbour.dao.tg.DesignDao;
import com.itbour.dto.com.TopicInfoDto;
import com.itbour.dto.tg.DesignPCInfoDto;
import com.itbour.dto.tg.DesignPageInfoDto;
import com.itbour.dto.tg.DesignInfoDto;
import com.itbour.dto.tg.DisUserdocDto;
import com.itbour.dto.tg.KeywordInfoDto;
import com.itbour.dto.tg.OrgInfoDto;
import com.itbour.dto.tg.OutlineInfoDto;
import com.itbour.dto.trade.TmplPriceInfoDto;
import com.itbour.dto.video.YjxPriceInfoDto;
import com.itbour.service.tg.DesignService;


/**
* 分页映射
* 
* copyright   itbour team 2016
* @author     xc
* 
* update yjxPrice kris liqi
*
*/

public class DesignServiceImpl implements DesignService {

	private DesignDao designDao;
	
	/**
	 * @param countKey
	 *            查询该表所有记录行的SQL语句ID
	 * @param sqlKey
	 *            需要查询记录的SQL语句ID
	 * @param param
	 *            传递给查询语句的参数
	 * @param pageNo
	 *            需要查询的实际页
	 * @param pageSize
	 *            每页记录行数
	 * @return page对象
	 */
	public Page pageQuery(Map<String,Object> param, Integer pageNo, Integer pageSize) {
		try {
			Page result = null;
			
			// 实际起始位置
			int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
			int totalSize = designDao.selectDesignCnt(param);
			
			while(totalSize >0 && totalSize <= skipResults){
				skipResults= skipResults - pageSize;
				pageNo = pageNo -1;
			}
			
			// 分页检索
			param.put("pageSize", pageSize);
			param.put("skipResults", skipResults);
			List<DesignInfoDto> data = designDao.selectDesignInfo(param);

			result = new JspPage(skipResults, totalSize, pageSize, data);
			return result;
		} finally {
			//clearSelectDataSource(dataSource);
		}
	}
	
	/**
	 * 获取 下架模板列表
	 */
	public Page pageQueryDesignOutReview(Map<String,Object> param, Integer pageNo, Integer pageSize) {
		try {
			Page result = null;
			
			// 实际起始位置
			int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
			int totalSize = designDao.selectOutDesignCnt(param);
			
			while(totalSize >0 && totalSize <= skipResults){
				skipResults= skipResults - pageSize;
				pageNo = pageNo -1;
			}
			
			// 分页检索
			param.put("pageSize", pageSize);
			param.put("skipResults", skipResults);
			List<DesignInfoDto> data = designDao.selectOutDesignInfo(param);
			
			result = new JspPage(skipResults, totalSize, pageSize, data);
			return result;
		} finally {
			//clearSelectDataSource(dataSource);
		}
	}
	
	public Page pageQueryTmplPrice(Map<String,Object> param, Integer pageNo, Integer pageSize) {
		try {
			Page result = null;
			
			// 实际起始位置
			int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
			int totalSize = designDao.selectTmplPriceCnt(param);
			
			while(totalSize >0 && totalSize <= skipResults){
				skipResults= skipResults - pageSize;
				pageNo = pageNo -1;
			}
			
			// 分页检索
			param.put("pageSize", pageSize);
			param.put("skipResults", skipResults);
			List<TmplPriceInfoDto> data = designDao.selectTmplPriceInfo(param);

			result = new JspPage(skipResults, totalSize, pageSize, data);
			return result;
		} finally {
			//clearSelectDataSource(dataSource);
		}
	}
	
	public Page getDisUserDocInfo(Map<String,Object> param, Integer pageNo, Integer pageSize) {
		try {
			Page result = null;
			// 实际起始位置
			int skipResults = JspPage.getStartOfPage(pageNo, pageSize);
			int totalSize = designDao.getDisignUserDocCnt(param);
			while(totalSize >0 && totalSize <= skipResults){
				skipResults= skipResults - pageSize;
				pageNo = pageNo -1;
			}
			// 分页检索
			param.put("pageSize", pageSize);
			param.put("skipResults", skipResults);
			List<DisUserdocDto> data = designDao.getDisignUserDocInfo(param);
			result = new JspPage(skipResults, totalSize, pageSize, data);
			return result;
		} finally {
			//clearSelectDataSource(dataSource);
		}
	}
	
	// 查询设计模版
	public List<DesignInfoDto> selectDesignInfo(Map<String,Object> param) {
		return designDao.selectDesignInfo(param);
	}
	public List<DesignPageInfoDto> selectDesignPageInfo(Map<String,Object> param) {
		return designDao.selectDesignPageInfo(param);
	}
	public List<DesignPCInfoDto> selectDesignPCInfo(Map<String,Object> param) {
		return designDao.selectDesignPCInfo(param);
	}

	// 更新设计模版信息
	public void updateDesignById(Map<String,Object> param) {
		designDao.updateDesignInfoById(param);
	}
	
	// 删除设计模版
	public void deleteDesignInfo(Map<String,Object> param) {
		designDao.deleteDesignLogic(param);
	}
	public void deleteDesignPageInfo(Map<String,Object> param) {
		designDao.deleteDesignPageLogic(param);
	}
	public void deleteDesignPCInfo(Map<String,Object> param) {
		designDao.deleteDesignPCLogic(param);
	}
	
	// 查询提纲
	public List<OutlineInfoDto> selectOutlineInfo(Map<String,Object> param) {
		return designDao.selectOutlineInfo(param);
	}
	
	// 查询组织
	public List<OrgInfoDto> selectOrgInfo(Map<String,Object> param) {
		return designDao.selectOrgInfo(param);
	}
	
	// 检索关键词信息
	public List<KeywordInfoDto> selectKeywordInfo(Map<String,Object> param){
		if(param !=null && param.containsKey("design_id")){
			return designDao.selectDesignKeywordInfo(param);
		}
		
		return designDao.selectKeywordInfo(param);
	}
	
	// 添加评审纪录
	public void insertReviewHis(Map<String,Object> param) {
		designDao.insertReviewHis(param);
	}
	
	// 检索热门专题信息
	public List<TopicInfoDto> selectTopicInfo(Map<String,Object> param){
		//return designDao.selectTopicInfo(param);
		//return designDao.selectTopicInfo2(param);
		return designDao.selectTopicInfo3(param);
	}
	
	// 模版价格增删改
	public void insertTmplPrice(Map<String,Object> param){
		designDao.insertTmplPrice(param);
	}
	public void deleteTmplPriceInfo(Map<String,Object> param){
		designDao.deleteTmplPriceLogic(param);
	}
	public void updateTmplPriceById(Map<String,Object> param){
		designDao.updateTmplPriceById(param);
	}

	public DesignDao getDesignDao() {
		return designDao;
	}

	public void setDesignDao(DesignDao designDao) {
		this.designDao = designDao;
	}
	
	
	// 检索套餐价格
	public List<YjxPriceInfoDto> selectPriceInfo(Map<String,Object> param){
		if(param !=null && param.containsKey("design_id")){
			return designDao.selectTgPriceInfo(param);
		}
		
		return designDao.selectPriceInfo(param);
	}
	// 添加视频套餐
	public boolean addPriceRInfo(Map<String, Object> parm) {
		try {
			designDao.addPriceRInfo(parm);// 添加视频价格套餐信息
			return true;
		} catch (Exception e) {
			return false;
		}
	}
	// 删除价格视频套餐
	public boolean delPriceRInfo(Map<String, Object> parm) {
		try {
			designDao.delPriceRInfo(parm);// 删除视频价格套餐
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	// 同步删除
	public void delTmplSetRInfo(Map<String, Object> parm) {
		designDao.delTmplSetRInfo(parm);
	}

	public void insertReview2His(Map<String, Object> param) {// 添加下架审核记录
		designDao.insertReview2His(param);
	}

}
